package fr.umlv.m2.jee.spij.service.tutorial;

import fr.umlv.m2.jee.spij.persistence.education.Tutorial;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.Date;

/**
 * @author mathieu mazzolini
 */
@Component("tutorialBean")
public class DisplayTutorial implements Serializable {

    /**
     * Primary key.
     */
    private long id;

    /**
     * Instructional date.
     */
    private Date date;

    /**
     * Instructional start time.
     */
    private Date startTime;

    /**
     * Instructional end time.
     */
    private Date endTime;

    /**
     * About teaching.
     */
    private String subject;

    /**
     * Contain of practice.
     */
    private String contain;

    /**
     * Correction of practice.
     */
    private String correction;

    /**
     * Link of practice in PDF.
     */
    private String linkSupport;

    /**
     * Link of correction in PDF.
     */
    private String linkCorrection;

    /**
     * Id of linked unit.
     */
    private long unit;

    /**
     * Name of unit.
     */
    private String unitName;

    /**
     * Default constructor
     */
    public DisplayTutorial() {
    }

    public DisplayTutorial(Tutorial tutorial) {
        if (tutorial != null)
            storeData(tutorial);
    }

    private void storeData(Tutorial tutorial) {
        setId(tutorial.getId());
        setSubject(tutorial.getSubject());
        setContain(tutorial.getContain());
        setCorrection(tutorial.getCorrection());

        if (tutorial.getDuration() != null) {
            setDate(tutorial.getDuration().getStart().toDate());
            setStartTime(tutorial.getDuration().getStart().toDate());
            setEndTime(tutorial.getDuration().getEnd().toDate());
        }

        setLinkSupport(tutorial.getLinkSupport());
        setLinkCorrection(tutorial.getLinkCorrection());

        if (tutorial.getUnit() != null) {
            setUnit(tutorial.getUnit());
        }

    }

    /**
     * @return
     */
    public long getId() {
        return id;
    }

    /**
     * @param id
     */
    public void setId(long id) {
        this.id = id;
    }

    // /**
    // * @return the duration
    // */
    // public Interval getDuration() {
    // return duration;
    // }
    //
    // /**
    // * @param duration the duration to set
    // */
    // public void setDuration(Interval duration) {
    // this.duration = duration;
    // }

    /**
     * @return the subject
     */
    public String getSubject() {
        return subject;
    }

    /**
     * @param subject the subject to set
     */
    public void setSubject(String subject) {
        this.subject = subject;
    }

    /**
     * @return the contain
     */
    public String getContain() {
        return contain;
    }

    /**
     * @param contain the contain to set
     */
    public void setContain(String contain) {
        this.contain = contain;
    }

    /**
     * @return the correction
     */
    public String getCorrection() {
        return correction;
    }

    /**
     * @param correction the correction to set
     */
    public void setCorrection(String correction) {
        this.correction = correction;
    }

    /**
     * @return the linkSupport
     */
    public String getLinkSupport() {
        return linkSupport;
    }

    /**
     * @param linkSupport the linkSupport to set
     */
    public void setLinkSupport(String linkSupport) {
        this.linkSupport = linkSupport;
    }

    /**
     * @return the linkCorrection
     */
    public String getLinkCorrection() {
        return linkCorrection;
    }

    /**
     * @param linkCorrection the linkCorrection to set
     */
    public void setLinkCorrection(String linkCorrection) {
        this.linkCorrection = linkCorrection;
    }

    /**
     * @return the unit
     */
    public long getUnit() {
        return unit;
    }

    /**
     * @param unit the unit to set
     */
    public void setUnit(long unit) {
        this.unit = unit;
    }

    /**
     * @return the unitName
     */
    public String getUnitName() {
        return unitName;
    }

    /**
     * @param unitName the unitName to set
     */
    public void setUnitName(String unitName) {
        this.unitName = unitName;
    }

    /**
     * @return the date
     */
    public Date getDate() {
        return new Date(date.getTime());
    }

    /**
     * @param date the date to set
     */
    public void setDate(Date date) {
        this.date = new Date(date.getTime());
    }

    /**
     * @return the startTime
     */
    public Date getStartTime() {
        return new Date(startTime.getTime());
    }

    /**
     * @param startTime the startTime to set
     */
    public void setStartTime(Date startTime) {
        this.startTime = new Date(startTime.getTime());
    }

    /**
     * @return the endTime
     */
    public Date getEndTime() {
        return new Date(endTime.getTime());
    }

    /**
     * @param endTime the endTime to set
     */
    public void setEndTime(Date endTime) {
        this.endTime = new Date(endTime.getTime());
    }

}
